---
title: Replication Code for Stacy, Darrian. "Wealth and Policymaking in the U.S. House
  of Representatives." Legislative Studies Quarterly
author: "Darrian Stacy (darrian.stacy@gmail.com)"
date: "May 20, 2025"
output: html_document
---

#Setup
```{r}
##Libraries
library(dplyr)

##Set the working directory 
setwd("path/to/your/file") 

##Open file location
data_list <- readRDS("~/path/to/your/file_location/stacy2025_replication.rds")

##load the data sets into the global environment
list2env(data_list, envir = .GlobalEnv) 


##See Online Supplemental Appendix for more details on variable descriptions and variable sources
```

#Figures 2 and 3
```{r}
ivs <- dat1 %>%
  group_by(bmt_quintile) %>%
  summarise(
    median_assets_2023 = median(asset_mean_23dollars),
    median_assets_2023_sd = sd(asset_mean_23dollars),
    medianIncome2 = median(medianIncome23),
    medianIncome2_sd = sd(medianIncome23),
    aged = mean(age), age_sd = sd(age),
    senior = mean(seniority), senior_sd = sd(seniority),
    stateleg = mean(state_leg), stateleg_sd = sd(state_leg),
    statelegprof = mean(state_leg_prof2, na.rm = TRUE), statelegprof_sd = sd(state_leg_prof2, na.rm=TRUE),
    majorit = mean(majority), majorit_sd = sd(majority),
    maj_lead = mean(maj_leader), maj_lead_sd = sd(maj_leader),
    min_leade = mean(min_leader), min_leade_sd = sd(min_leader),
    speake = mean(speaker), speake_sd = sd(speaker),
    chai = mean(chair), chai_sd = sd(chair),
    subch = mean(subchr), subch_sd = sd(subchr),
    powe = mean(power), powe_sd = sd(power),
    meddis = mean(meddist), meddis_sd = sd(meddist),
    femal = mean(female), femal_sd = sd(female),
    afa = mean(afam), afa_sd = sd(afam),
    latin = mean(latino), latin_sd = sd(latino),
    deleg_siz = mean(deleg_size), deleg_siz_sd = sd(deleg_size),
    votepc = mean(votepct2), votepc_sd = sd(votepct2),
    majdis = mean(majdist), majdis_sd = sd(majdist),
    count = n(),
    .groups = "drop"
  ) %>%
  mutate(
   
    across(ends_with("_sd"), ~ . / sqrt(count), .names = "{.col}_se"),

    median_assets_2023_lower_ci = median_assets_2023 - qt(0.975, count - 1) * median_assets_2023_sd_se,
    median_assets_2023_upper_ci = median_assets_2023 + qt(0.975, count - 1) * median_assets_2023_sd_se,

    medianIncome2_lower_ci = medianIncome2 - qt(0.975, count - 1) * medianIncome2_sd_se,
    medianIncome2_upper_ci = medianIncome2 + qt(0.975, count - 1) * medianIncome2_sd_se,

    age_lower_ci = aged - qt(0.975, count - 1) * age_sd_se,
    age_upper_ci = aged + qt(0.975, count - 1) * age_sd_se,

    senior_lower_ci = senior - qt(0.975, count - 1) * senior_sd_se,
    senior_upper_ci = senior + qt(0.975, count - 1) * senior_sd_se,

    stateleg_lower_ci = stateleg - qt(0.975, count - 1) * stateleg_sd_se,
    stateleg_upper_ci = stateleg + qt(0.975, count - 1) * stateleg_sd_se,

    statelegprof_lower_ci = statelegprof - qt(0.975, count - 1) * statelegprof_sd_se,
    statelegprof_upper_ci = statelegprof + qt(0.975, count - 1) * statelegprof_sd_se,

    majorit_lower_ci = majorit - qt(0.975, count - 1) * majorit_sd_se,
    majorit_upper_ci = majorit + qt(0.975, count - 1) * majorit_sd_se,

    maj_lead_lower_ci = maj_lead - qt(0.975, count - 1) * maj_lead_sd_se,
    maj_lead_upper_ci = maj_lead + qt(0.975, count - 1) * maj_lead_sd_se,

    min_leade_lower_ci = min_leade - qt(0.975, count - 1) * min_leade_sd_se,
    min_leade_upper_ci = min_leade + qt(0.975, count - 1) * min_leade_sd_se,

    speake_lower_ci = speake - qt(0.975, count - 1) * speake_sd_se,
    speake_upper_ci = speake + qt(0.975, count - 1) * speake_sd_se,

    chai_lower_ci = chai - qt(0.975, count - 1) * chai_sd_se,
    chai_upper_ci = chai + qt(0.975, count - 1) * chai_sd_se,

    subch_lower_ci = subch - qt(0.975, count - 1) * subch_sd_se,
    subch_upper_ci = subch + qt(0.975, count - 1) * subch_sd_se,

    powe_lower_ci = powe - qt(0.975, count - 1) * powe_sd_se,
    powe_upper_ci = powe + qt(0.975, count - 1) * powe_sd_se,

    meddis_lower_ci = meddis - qt(0.975, count - 1) * meddis_sd_se,
    meddis_upper_ci = meddis + qt(0.975, count - 1) * meddis_sd_se,

    femal_lower_ci = femal - qt(0.975, count - 1) * femal_sd_se,
    femal_upper_ci = femal + qt(0.975, count - 1) * femal_sd_se,

    afa_lower_ci = afa - qt(0.975, count - 1) * afa_sd_se,
    afa_upper_ci = afa + qt(0.975, count - 1) * afa_sd_se,

    latin_lower_ci = latin - qt(0.975, count - 1) * latin_sd_se,
    latin_upper_ci = latin + qt(0.975, count - 1) * latin_sd_se,

    deleg_siz_lower_ci = deleg_siz - qt(0.975, count - 1) * deleg_siz_sd_se,
    deleg_siz_upper_ci = deleg_siz + qt(0.975, count - 1) * deleg_siz_sd_se,

    votepc_lower_ci = votepc - qt(0.975, count - 1) * votepc_sd_se,
    votepc_upper_ci = votepc + qt(0.975, count - 1) * votepc_sd_se,

    majdis_lower_ci = majdis - qt(0.975, count - 1) * majdis_sd_se,
    majdis_upper_ci = majdis + qt(0.975, count - 1) * majdis_sd_se
  ) %>%
  mutate(across(where(is.numeric), ~ round(., 2)))

```



#Table A2
```{r}
anova_model <- aov(asset_mean ~ quintile, data = dat2)
anova_results <- summary(anova_model)
tukey_results <- TukeyHSD(anova_model)
```

#Table A3 (Figure 4)
```{r}
lm1 <- lm(lesclassic ~ q1_2 + q5_2,
                  data = dat2)

summary(lm1)

lm2 <- (lm(lesclassic ~ q1_2 + q5_2 + log(medianIncome) + age + age_sq + seniority + sensq + state_leg*state_leg_prof + majority + maj_leader + min_leader + speaker + chair + subchr + power + meddist + female + afam + latino + deleg_size + votepct  + votepct_sq + factor(congNum),
          data = dat2))

summary(lm2)

lm3 <- lm(lesclassic ~ q1_2 + q5_2   + age + age_sq + seniority + sensq + state_leg*state_leg_prof + majority + maj_leader + min_leader + speaker + chair + subchr + power + meddist + female + afam + latino + deleg_size + votepct  + votepct_sq + log(CAND_LOANS_adj) + log(medianIncome)+ factor(congNum), data = dat3)

summary(lm3)
```

#Table A4 (Figure 5)
```{r}
lm_bills <- lm(allbill1 ~ q1_2 + q5_2 + log(medianIncome)  + age + age_sq  + seniority + sensq + state_leg*state_leg_prof + majority + maj_leader + min_leader + speaker + chair + subchr + power + meddist + female + afam + latino + deleg_size + votepct  + votepct_sq + factor(congNum), data = dat2) 

summary(lm_bills)


lm_aic <- lm(allaic1 ~ q1_2 + q5_2 + log(medianIncome)  + age + age_sq  + seniority + sensq + state_leg*state_leg_prof + majority + maj_leader + min_leader + speaker + chair + subchr + power + meddist + female + afam + latino + deleg_size + votepct  + votepct_sq + factor(congNum), 
             data = dat2[dat2$allbill1>0,]) 

summary(lm_aic)


lm_abc <- lm(allabc1 ~ q1_2 + q5_2 + log(medianIncome)  + age + age_sq  +seniority + sensq + state_leg*state_leg_prof + majority + maj_leader + min_leader + speaker + chair + subchr + power + meddist + female + afam + latino + deleg_size + votepct  + votepct_sq + factor(congNum), 
             data = dat2[dat2$allaic1>0,]) 

summary(lm_abc)


lm_pass <- lm(allpass1 ~ q1_2 + q5_2 + log(medianIncome)  + age + age_sq + seniority + sensq + state_leg*state_leg_prof + majority + maj_leader + min_leader + speaker + chair + subchr + power + meddist + female + afam + latino + deleg_size + votepct  + votepct_sq + factor(congNum), 
             data = dat2[dat2$allabc1>0,]) 

summary(lm_pass)

lm_law <- lm(alllaw1 ~ q1_2 + q5_2 + log(medianIncome)  + age + age_sq + seniority + sensq + state_leg*state_leg_prof + majority + maj_leader + min_leader + speaker + chair + subchr + power + meddist + female + afam + latino + deleg_size + votepct  + votepct_sq + factor(congNum), 
             data = dat2[dat2$allpass1>0,]) 

summary(lm_law)
```

#Table A5 (Figures 6 and 7)
```{r}
lm_parties <- lm(lesclassic ~  q1_min + q5_min + q1_maj + q5_maj + log(medianIncome)  + age + age_sq + seniority + sensq + state_leg*state_leg_prof + majority + maj_leader + min_leader + speaker + chair + subchr + power + meddist + female + afam + latino + deleg_size + votepct  + votepct_sq + factor(congNum), data = dat2)

summary(lm_parties)

lm_bills2 <- lm(allbill1 ~  q1_min + q5_min + q1_maj + q5_maj + log(medianIncome)  + age + age_sq + seniority + sensq + state_leg*state_leg_prof + majority + maj_leader + min_leader + speaker + chair + subchr + power + meddist + female + afam + latino + deleg_size + votepct  + votepct_sq + factor(congNum), data = dat2)

summary(lm_bills2)


lm_aic2 <- lm(allaic1 ~  q1_min + q5_min + q1_maj + q5_maj + log(medianIncome)  + age + age_sq + seniority + sensq + state_leg*state_leg_prof + majority + maj_leader + min_leader + speaker + chair + subchr + power + meddist + female + afam + latino + deleg_size + votepct  + votepct_sq + factor(congNum), data = dat2[dat2$allbill1>0,])

summary(lm_aic2)


lm_abc2 <- lm(allabc1 ~ q1_min + q5_min + q1_maj + q5_maj + log(medianIncome)   + age + age_sq + seniority + sensq + state_leg * state_leg_prof + majority + maj_leader + min_leader + speaker + chair + subchr + power + meddist + female + afam + latino + deleg_size + votepct  + votepct_sq + factor(congNum), data = dat2[dat2$allaic1>0,])

summary(lm_abc2)

lm_pass2 <- lm(allpass1 ~  q1_min + q5_min + q1_maj + q5_maj + log(medianIncome)  + age + age_sq + seniority + sensq + state_leg*state_leg_prof + majority + maj_leader + min_leader + speaker + chair + subchr + power + meddist + female + afam + latino + deleg_size + votepct  + votepct_sq  + factor(congNum), data = dat2[dat2$allabc1>0,])

summary(lm_pass2)

lm_law2 <- lm(alllaw1 ~ q1_min + q5_min + q1_maj + q5_maj + log(medianIncome) +  age + age_sq + seniority + sensq + state_leg*state_leg_prof + majority + maj_leader + min_leader + speaker + chair + subchr + power + meddist + female + afam + latino + deleg_size + votepct  + votepct_sq + factor(congNum), data = dat2[dat2$allpass1>0,])

summary(lm_law2)

```

#Table A6
```{r}
lm_nochairs <- lm(lesclassic ~  q1_min + q5_min + q1_maj + q5_maj + log(medianIncome)  + age + age_sq + seniority + sensq + state_leg*state_leg_prof + majority + maj_leader + min_leader + speaker  + power + meddist + female + afam + latino + deleg_size + votepct  + votepct_sq + factor(congNum), data = dat2[dat2$chair==0 & dat2$subchr==0,])

summary(lm_nochairs)

lm_chairs <- lm(lesclassic ~  q1_min + q5_min + q1_maj*chair + q5_maj*chair + log(medianIncome)  + age + age_sq + seniority + sensq + state_leg*state_leg_prof + majority + maj_leader + min_leader + speaker + chair + subchr + power + meddist + female + afam + latino + deleg_size + votepct  + votepct_sq + factor(congNum), data = dat2)

summary(lm_chairs)
```

#Table A7 (Figure 8)
```{r}
lm_seniority <- lm(lesclassic ~ first_q1 * seniority_group + 
                                    first_q5 * seniority_group + log(medianIncome) + 
                                    age + age_sq + sensq + state_leg*state_leg_prof + 
                                    majority + maj_leader + min_leader + speaker + chair + 
                                    subchr + power + meddist + female + afam + latino + 
                                    deleg_size + votepct + votepct_sq + factor(congNum), 
                        data = dat4)

summary(lm_seniority)
```

#Table A8
```{r}
lm_alt <- lm(lesclassic ~ relevel(factor(quintile), ref = "3")  + log(medianIncome) + age + age_sq + seniority + sensq + state_leg + state_leg_prof + majority + maj_leader + min_leader + speaker + chair + subchr + power + meddist + female + afam + latino + deleg_size + votepct  + votepct_sq + factor(congNum),
          data = dat2)

summary(lm_alt)
```


#Table B2
```{r}
summary(lm(log(tot_govops + 0.1) ~ q1 + q5 + factor(congress),data = dat5[dat5$congress <=112,])) 

summary(lm(log(tot_publands + 0.1) ~ q1 + q5 + factor(congress),data = dat5[dat5$congress <=112,]))

summary(lm(log(tot_dcommerce + 0.1) ~ q1 + q5 + factor(congress),data = dat5[dat5$congress <=112,])) 

summary(lm(log(tot_defense + 0.1) ~ q1 + q5 + factor(congress),data = dat5[dat5$congress <=112,])) 

summary(lm(log(tot_labor + 0.1) ~ q1 + q5 + factor(congress), data = dat5[dat5$congress <=112,]))

summary(lm(log(tot_lawcrime + 0.1) ~ q1 + q5 + factor(congress),data = dat5[dat5$congress <=112,])) 

summary(lm(log(tot_enviro + 0.1) ~ q1 + q5 + factor(congress),data = dat5[dat5$congress <=112,])) 

summary(lm(log(tot_energy + 0.1) ~ q1 + q5 + factor(congress),data = dat5[dat5$congress <=112,])) 

summary(lm(log(tot_intlaffairs + 1) ~ q1 + q5 + factor(congress),data = dat5[dat5$congress <=112,]))

summary(lm(log(tot_welfare + 0.1) ~ q1 + q5 + factor(congress),data = dat5[dat5$congress <= 114,])) 

summary(lm(log(tot_trade + 0.1) ~ q1 + q5 + factor(congress),data = dat5[dat5$congress <=112,]))

summary(lm(log(tot_edu + 0.1) ~ q1 + q5 + factor(congress), data = dat5[dat5$congress <=112,])) 

summary(lm(log(tot_health + 0.1) ~ q1 + q5 + factor(congress), data = dat5[dat5$congress <=112,])) 

summary(lm(log(tot_civil + 0.1) ~ q1 + q5 + factor(congress), data = dat5[dat5$congress <=112,]))

summary(lm(log(tot_housing + 0.1) ~ q1 + q5 + factor(congress),data = dat5[dat5$congress <=112,]))

summary(lm(log(tot_transp + 0.1) ~ q1 + q5 + factor(congress),data = dat5[dat5$congress <=112,]))

summary(lm(log(tot_ag + 0.1) ~ q1 + q5 + factor(congress), data = dat5[dat5$congress <=112,])) 

summary(lm(log(tot_tech + 0.1) ~ q1 + q5 + factor(congress),data = dat5[dat5$congress <=112,])) 

summary(lm(log(tot_macroecon + 0.1) ~ q1 + q5 + factor(congress), data = dat5[dat5$congress <=112,]))


summary(lm(log(tot_immigrat + 0.1) ~ q1 + q5 + factor(congress),data = dat5[dat5$congress <=112,]))

summary(lm(log(tot_culture + 0.1) ~ q1 + q5 + factor(congress),data = dat5[dat5$congress <=112,]))

summary(lm(log(tot_misc + 0.1) ~ q1 + q5 + factor(congress),data = dat5[dat5$congress <=112,])) 

```

#Table C1
```{r}
summary(lm(log(Total_Amount_of_Contributions+1) ~ q1 + q5 + factor(year), data = dat6))

summary(lm(Total_Number_of_Contributions ~ q1 + q5 + factor(year), data = dat6))


```

#Table C2
```{r}
summary(lm(lesclassic ~ minority_q1 + majority_q1 + minority_q5 + majority_q5  + 
             log(Total_Amount_of_Contributions+1) + Total_Number_of_Contributions + 
             age + age_sq + seniority + sensq + state_leg + state_leg_prof + 
             majority + maj_leader + min_leader + speaker + chair + subchr +
             power + meddist + female + afam + latino + deleg_size + 
             votepct  + votepct_sq  + log(medianIncome) + as.factor(congress), data = dat7))
```


#Table C3
```{r}
summary(lm(lesclassic ~  elite_university + seniority + sensq + state_leg*state_leg_prof + majority + maj_leader + min_leader + speaker + chair + subchr + power + meddist + female + afam + latino + deleg_size + votepct  + votepct_sq + factor(congNum),data = dat8))


summary(lm(lesclassic ~ q1_2 + q5_2 + elite_university  + age + age_sq + seniority + sensq + state_leg*state_leg_prof + majority + maj_leader + min_leader + speaker + chair + subchr + power + meddist + female + afam + latino + deleg_size + votepct  + votepct_sq + log(medianIncome) + factor(congNum), data = dat8))
```

